package Shangji1;

/**
 * 操作工厂类
 */
public class OperationFactory {

    /**
     * 根据操作符创建相应的操作实例
     * @param operator 操作符 (+, -, *, /)
     * @return 操作实例
     */
    public static Operation createOperation(String operator) {
        Operation operation = null;

        switch (operator) {
            case "+":
                operation = new AddOperation();
                break;
            case "-":
                operation = new SubtractOperation();
                break;
            case "*":
                operation = new MultiplyOperation();
                break;
            case "/":
                operation = new DivideOperation();
                break;
            default:
                throw new IllegalArgumentException("不支持的运算符: " + operator);
        }

        return operation;
    }
}
